#include <cstdio>
#include <cstring>
#include <queue>
const int N = 2010;
int n, m, t, cnt, heads[N], dis[N], tot[N];
struct Edge {
  int v, nxt, c;
} e[6010];
inline void add(int u, int v, int c) {
  e[++cnt].c = c, e[cnt].v = v, e[cnt].nxt = heads[u], heads[u] = cnt;
}
bool vis[N];
inline bool spfa() {
  std::queue<int> q;
  memset(dis, 0x3f, sizeof(dis));
  q.push(1);
  dis[1] = 0, tot[1] = 1, vis[1] = true;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    vis[x] = false;
    for (int i = heads[x]; i; i = e[i].nxt) {
      int v = e[i].v;
      if (dis[v] > dis[x] + e[i].c) {
        dis[v] = dis[x] + e[i].c;
        if (!vis[v]) {
          if (++tot[v] > n) return true;
          q.push(v);
          vis[v] = true;
        }
      }
    }
  }
  return false;
}
int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
  freopen("NegativeCycle.in", "r", stdin);
  freopen("NegativeCycle.out", "w", stdout);
#endif
#endif

  scanf("%d", &t);
  int u, v, c;
  while (t--) {
    scanf("%d%d", &n, &m);
    cnt = 0;
    memset(heads, 0, sizeof(heads));
    memset(tot, 0, sizeof(tot));
    memset(vis, 0, sizeof(vis));
    for (int i = 1; i <= m; ++i) {
      scanf("%d%d%d", &u, &v, &c);
      add(u, v, c);
      if (c >= 0) add(v, u, c);
    }
    if (spfa()) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
  }
  return 0;
}